<template>
	<view>
		<u-navbar title="群公告">
			<view v-if="canEdit" slot="right" class="u-p-x-16 u-p-y-4 u-m-r-30 radius bg-blue" @tap="save" >
				<text class="u-font-28">保存</text>
			</view>
		</u-navbar>
		<view class="u-m-t-20 bg-white u-p-30">
			<textarea class="textarea u-font-28" maxlength="160" v-model="notice" placeholder="" :disable="!canEdit"/>
			<view class="text-gray u-text-right u-m-t-40">
				<text>{{notice.length}}/160</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {goback} from '@/utils/util.js'
	import {state} from "../bus.js"
	import {editGroupNotice} from "@/api/addr.js"
	import {mapGetters} from "vuex"
	export default {
		data() {
			return {
				notice:''
			};
		},
		computed:{
			...mapGetters('user',['userId']),
			canEdit(){
				return state.power.vest=='群主'||state.power.vest=='管理员'
			}
		},
		onLoad(){
			this.notice = state.info.notice
		},
		methods:{
			async save(){
				if(this.save.lock){
					return
				}
				try{
					this.save.lock = true
					
					await editGroupNotice({id:state.info.id,notice:this.notice})
					state.info.notice = this.notice
					goback()
				}finally{
					this.save.lock = false
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.textarea{
		width: 100%;
		height: 200rpx;
	}
</style>
